<template>
  <div style="height: 100px">
    <!--卡片-->
    <el-card class="box-card">
      <!--定义面包屑-->
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>客户管理</el-breadcrumb-item>
        <el-breadcrumb-item>优惠券记录</el-breadcrumb-item>
      </el-breadcrumb>
      <el-divider></el-divider>
      <div style="">
        <!-- 表单的搜索框 :model="双向绑定表单的数据" -->
        <el-form :inline="true" :model="couponHistorySelect"  class="demo-form-inline">
          <el-form-item >
            <el-input v-model="couponHistorySelect.id" placeholder="请输入优惠券记录id"></el-input>
          </el-form-item>
          <el-form-item >
            <el-input v-model="couponHistorySelect.couponId" placeholder="请输入优惠券id"></el-input>
          </el-form-item>
          <el-form-item >
            <el-input v-model="couponHistorySelect.memberId" placeholder="请输入用户id"></el-input>
          </el-form-item>
          <el-form-item >
            <el-select v-model="couponHistorySelect.getType" placeholder="获取类型">
              <el-option
                  v-for="item in optionGetType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item >
            <div class="block">
              <el-date-picker
                  v-model="couponHistorySelect.createTime"
                  align="right"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  :picker-options="pickerOptions">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item >
            <el-input v-model="couponHistorySelect.username" placeholder="请输入用户账号"></el-input>
          </el-form-item>
          <el-form-item >
            <el-select v-model="couponHistorySelect.useStatus" placeholder="使用状态">
              <el-option
                  v-for="item in optionUseStatus"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item >
            <div class="block">
              <el-date-picker
                  v-model="couponHistorySelect.useTime"
                  align="right"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择使用时间"
                  :picker-options="pickerOptions">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item >
            <el-input v-model="couponHistorySelect.orderSn" placeholder="订单编号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="initcouponHistoryTable">查询</el-button>
          </el-form-item>
        </el-form>
        <!--数据表格-->
        <template>
          <el-table
              :data="tableData"
              :border="true"
              stripe
              style="width:100%">
            <!--            height="666"-->
            <el-table-column
                prop="id"
                label="优惠券记录id"
                fixed="left"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="couponId"
                label="优惠券id"
                fixed="left"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="memberId"
                label="会员id"
                fixed="left"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="username"
                label="会员账号"
                fixed="left"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建记录时间"
                sortable
            >
            </el-table-column>
            <el-table-column
                prop="getType"
                label="获取类型"
                sortable>
              <template slot-scope="scope">
                <span v-if="scope.row.getType===0">后台赠送</span>
                <span v-if="scope.row.getType===1">主动获取</span>
              </template>
            </el-table-column>
            <el-table-column
                prop="useStatus"
                label="使用状态"
                sortable>
              <template slot-scope="scope">
                <span v-if="scope.row.useStatus===0">未使用</span>
                <span v-if="scope.row.useStatus===1">已使用</span>
                <span v-if="scope.row.useStatus===2">已过期</span>
              </template>
            </el-table-column>
            <el-table-column
                prop="useTime"
                label="使用时间"
                sortable>
            </el-table-column>
            <el-table-column
                prop="orderSn"
                label="订单编号"
                sortable>
            </el-table-column>
          </el-table>
          <!--分页-->
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </template>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "CouponRecord",
  data(){
    return {
      //条件搜索对象
      couponHistorySelect:{},
      //表格数据
      tableData:[],
      //每页显示的条数
      pageSize: 5,
      //当前的显示的页码
      currentPage:1,
      //总条数
      total:0,
      //分配角色框的显示
      fenRoleDialog:false,
      //表单元素
      ruleForm:{},
      //表单校验规则
      rules: {
        name: [
          { required: true, message: '请输入会员名称', trigger: 'blur' },
        ],
      },
      titleName:"",
      optionGetType:[{
        value: 0,
        label: '后台赠送'
      }, {
        value: 1,
        label: '主动获取'
      }],
      optionUseStatus:[{
        value: 0,
        label: '未使用'
      }, {
        value: 1,
        label: '已使用'
      }, {
        value: 2,
        label: '已过期'
      }],
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
    }
  },
  //加载玩调用
  created() {
    this.initcouponHistoryTable();
  },

  methods:{
    handleClose(){
    },
    //1.初始化用户列表
    initcouponHistoryTable(){
      var that= this;
      this.$http.post(`/members/couponHistory/get/${this.currentPage}/${this.pageSize}`,this.couponHistorySelect).then(function (r) {
        that.tableData=r.data.result.records;
        that.total=r.data.result.total;
      })
    },
    //当改变没有显示的条数时触发该方法
    handleSizeChange(y){
      this.pageSize=y;
      this.initcouponHistoryTable();
    },
    //切换页码时触发该方法
    handleCurrentChange(y){
      this.currentPage=y;
      this.initcouponHistoryTable();
    }
  }
}
</script>

<style scoped>

</style>
